package com.com.effectivejava.generics.examples;

import com.com.effectivejava.generics.util.Child;
import com.com.effectivejava.generics.util.GrandChild;
import com.com.effectivejava.generics.util.GrandParent;
import com.com.effectivejava.generics.util.Parent;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
 * Created by pankaj on 7/19/14.
 */
public class AddT4 {
    static Logger logger = Logger.getLogger(AddT4.class.getName());

    static {
        logger.setParent(Logger.getLogger(AddT4.class.getPackage().getName()));
    }

    public static void main(String[] args) {
        //====================================================================
        //ist<Parent> objectsToParent = new ArrayList<Object>();
        List<Parent> parentsToParents = new ArrayList<Parent>();
        //List<Parent> parentsToChildren = new ArrayList<Child>();
        //List<Parent> parentsToGrandChildren = new ArrayList<GrandChild>();


        //====================================================================
        //List<? extends Parent> parentsToEObjects = new ArrayList<Object>();
        List<? extends Parent> parentsToEParents = new ArrayList<Parent>();
        List<? extends Parent> parentsToEChildren = new ArrayList<Child>();
        List<? extends Parent> parentsToEGrandChildren = new ArrayList<GrandChild>();

        //Cannot add anything but null;
        //Case1: if Child is added where GrandChild is the type. it would cause a problem.
        // How? we would call methods of GrandChild behaviour where Child is expected.
        //Case2: we would look for Integer where actual object is Long.
        // it would cause a real problem.
        parentsToEParents.add(null);

        //Cannot get anything but Parent, GrandParent or Object.
        for(Object n : parentsToEParents){

        }


        //====================================================================

        List<? super Parent> parentsToSObjects = new ArrayList<Object>();
        List<? super Parent> parentsToSGrandParents = new ArrayList<GrandParent>();
        List<? super Parent> parentsToSParents = new ArrayList<Parent>();

        parentsToSParents.add(new Parent());
        parentsToSParents.add(new Child());
        parentsToSParents.add(new GrandChild());

        for(Object gp : parentsToSParents){

        }
        //List<? super Parent> parentsToSChildren = new ArrayList<Child>();
        //List<? super Parent> parentsToSGrandChildren = new ArrayList<GrandChild>();

    }


}

